package com.yyx.server.controller;


import com.yyx.server.pojo.Position;
import com.yyx.server.service.PositionService;
import com.yyx.server.vo.ResultVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

/**
 * 职位管理
 * <p>
 *  前端控制器
 * </p>
 *
 * @author YongXin
 * @since 2021-07-24
 */
@RestController
@RequestMapping("/system/basic/pos")
public class PositionController {

    @Autowired
    private PositionService positionService;
    @ApiOperation("获取所有职位信息")
    @GetMapping("/")
    public List<Position> getAllPosition(){
        return positionService.list();
    }
    @ApiOperation("添加职位信息")
    @PostMapping("/")
    public ResultVo addPosition(@RequestBody Position position){
        position.setCreateDate(LocalDateTime.now());
        if (positionService.save(position)){
            return ResultVo.success("添加成功");
        }
        return ResultVo.error("添加失败");
    }
    @ApiOperation("更新职位信息")
    @PutMapping("/")
    public ResultVo updPosition(@RequestBody Position position){
        if (positionService.updateById(position)){
            return ResultVo.success("更新成功");
        }
        return ResultVo.error("更新失败");
    }
    @ApiOperation("删除职位信息")
    @DeleteMapping("/{id}")
    public ResultVo delPosition(@PathVariable Integer id){
        if (positionService.removeById(id)){
            return ResultVo.success("删除成功");
        }
        return ResultVo.error("删除失败");
    }
    @ApiOperation("批量删除职位信息")
    @DeleteMapping("/")
    public ResultVo delPositionByIds(Integer[] ids){
        if (positionService.removeByIds(Arrays.asList(ids))){
            return ResultVo.success("删除成功");
        }
        return ResultVo.error("删除失败");
    }
}

